$OpenBSD: patch-deps_npm_node_modules_node-gyp_lib_install_js,v 1.6 2014/09/24 18:17:27 abieber Exp $

Allow building of sub-packages (ie. node-sqlite3) with USE_SYSTRACE
set, also prevents downloading of the node distfile again.

--- deps/npm/node_modules/node-gyp/lib/install.js.orig	Tue Sep 16 16:47:52 2014
+++ deps/npm/node_modules/node-gyp/lib/install.js	Thu Sep 18 09:53:33 2014
@@ -225,38 +225,19 @@ function install (gyp, argv, callback) {
         return
       }
 
-      var req = download(tarballUrl)
-      if (!req) return
-
-      // something went wrong downloading the tarball?
-      req.on('error', function (err) {
-        badDownload = true
-        cb(err)
-      })
-
-      req.on('close', function () {
-        if (extractCount === 0) {
-          cb(new Error('Connection closed while downloading tarball file'))
+      // OpenBSD fix
+      var filePath = '${PREFIX}/lib/node/${DISTFILES}';
+      fs.stat(filePath, function(err, stat) {
+        if (err) {
+          throw err;
+        } else {
+          fs.createReadStream(filePath)
+            .pipe(gunzip)
+            .pipe(extracter)
         }
       })
+      // OpenBSD fix
 
-      req.on('response', function (res) {
-        if (res.statusCode !== 200) {
-          badDownload = true
-          cb(new Error(res.statusCode + ' status code downloading tarball'))
-          return
-        }
-        // content checksum
-        getContentSha(res, function (_, checksum) {
-          var filename = path.basename(tarballUrl).trim()
-          contentShasums[filename] = checksum
-          log.verbose('content checksum', filename, checksum)
-        })
-
-        // start unzipping and untaring
-        req.pipe(gunzip).pipe(extracter)
-      })
-
       // invoked after the tarball has finished being extracted
       function afterTarball () {
         if (badDownload) return
@@ -306,39 +287,17 @@ function install (gyp, argv, callback) {
       }
 
       function downloadShasums(done) {
-        var shasumsFile = (checksumAlgo === 'sha256') ? 'SHASUMS256.txt' : 'SHASUMS.txt'
-        log.verbose('check download content checksum, need to download `' + shasumsFile + '`...')
-        var shasumsPath = path.resolve(devDir, shasumsFile)
-          , shasumsUrl = distUrl + '/v' + version + '/' + shasumsFile
-
-        log.verbose('checksum url', shasumsUrl)
-        var req = download(shasumsUrl)
-        if (!req) return
-        req.on('error', done)
-        req.on('response', function (res) {
-          if (res.statusCode !== 200) {
-            done(new Error(res.statusCode + ' status code downloading checksum'))
-            return
-          }
-
-          var chunks = []
-          res.on('data', function (chunk) {
-            chunks.push(chunk)
-          })
-          res.on('end', function () {
-            var lines = Buffer.concat(chunks).toString().trim().split('\n')
-            lines.forEach(function (line) {
-              var items = line.trim().split(/\s+/)
-              if (items.length !== 2) return
-
-              // 0035d18e2dcf9aad669b1c7c07319e17abfe3762  ./node-v0.11.4.tar.gz
-              var name = items[1].replace(/^\.\//, '')
-              expectShasums[name] = items[0]
-            })
-
-            log.verbose('checksum data', JSON.stringify(expectShasums))
-            done()
-          })
+        var shasum = crypto.createHash('sha1')
+        var filePath = '${PREFIX}/lib/node/${DISTFILES}'
+        var s = fs.ReadStream(filePath);
+        s.on('data', function(d) {
+          shasum.update(d);
+        })
+        s.on('end', function() {
+          var d = shasum.digest('hex');
+          expectShasums['${DISTFILES}'] = d
+          log.verbose('`SHASUMS.txt` data', JSON.stringify(expectShasums))
+          done()
         })
       }
 
